export function copyValue(value) {
  try {
    let oInput = document.createElement('input')
    oInput.value = value
    document.body.appendChild(oInput)
    oInput.select() // 选择对象;
    document.execCommand('Copy') // 执行浏览器复制命令
    oInput.remove()
  } catch (error) {
    console.error('复制失败: ', error)
    return false
  }
  return true
}

/**
 * 从缓存查询候选人变量之前的值
 * @param {} variable 
 */
export function getCandiddataUser(variable) {
  let canUser = window.localStorage.getItem("CandiddataUser") || null
  if(canUser) {
    canUser = JSON.parse(canUser)
  } else {
    canUser = {}
  }
  if (variable in canUser) {
    return canUser[variable]
  } else {
    return null
  }

}

/**
 * 存储userid到缓存
 * @param {} variable 
 * @param {} userid 
 */
export function setCandiddataUser(variable, userid) {
  let canUser = window.localStorage.getItem("CandiddataUser") || null
  if(canUser == null) {
    canUser = {}
  } else {
    canUser = JSON.parse(canUser)
  }
  
  canUser[variable] = userid
  window.localStorage.setItem("CandiddataUser", JSON.stringify(canUser))
}